import uniqid from 'uniqid';
// import reduce = require('image-blob-reduce')();

export async function resizeImage(file: File | Blob) {
  // eslint-disable-next-line @typescript-eslint/no-var-requires
  const reduce = require('image-blob-reduce')();
  const blob = new Blob([file], { type: 'image/jpeg' });
  const resizedBlob = await reduce.toBlob(blob, { max: 1024 });
  const resizedFile = new File([resizedBlob], `${uniqid()}.jpeg`);

  return resizedFile;
}

export const createPreviewMedia = (media: File | Blob) =>
  Object.assign(media, {
    preview: URL.createObjectURL(media),
    uniqId: uniqid(),
  });
